package org.getOffer;

/**
 * @Author yu
 * @Date 2021/7/6
 */
public class Practice11 {

    public static void main(String[] args) {

        Practice11 practice11=new Practice11();
        int[] ints={3,4,5,1,2};
        System.out.println(practice11.minArray(ints));

    }

    public int minArray(int[] numbers) {

        int[] arr = new int[numbers.length];

        int min = numbers[0];

        int temp = 0,temp2=0;

        for (int i:numbers){
            if (min>i){
                arr[temp++]=i;
                continue;
            }
            temp2++;
        }

        for (int i=0;i<temp2;i++){
            arr[temp++]=numbers[i];
        }

        return arr[0];

    }

    /**
     *    二分法：
     *    public int minArray(int[] numbers) {
     *         int i = 0, j = numbers.length - 1;
     *         while (i < j) {
     *             int m = (i + j) / 2;
     *             if (numbers[m] > numbers[j]) i = m + 1;
     *             else if (numbers[m] < numbers[j]) j = m;
     *             else j--;
     *         }
     *         return numbers[i];
     *     }
     */

}
